    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>正则之验证电话号码</title>
        <style>
            .wrong{
                color: crimson;
            }
            .right{
                color: chartreuse;
            }
            .cellphone{
                color: #2b0ccc;
                font-size: 40px;
            }
        </style>
    </head>
    <script>
        window.onload=function () {
            //正则两种赋值方式
            // var reg2 = /def/;
            // var reg1 = new RegExp(/abc/);
//需求：要求号码是010-3xxxxxxxx或者02xx-3xxxxxxx 的电话号码
            var inpt=document.getElementsByTagName('input')[0];
            var span=document.getElementsByTagName('span')[0];
            // var reg=/^1[3456789]\d{9}$/;
            var reg1= new RegExp(/^1[3456789]\d{9}$/);
            var regTest=/a{1,3}/;

            //以1为开头，第二位在3456789中任选一位，剩下9位为正整数就行
            // var regExp2=new RegExp((/^(010)-3\d{7}$/)|(/^0[23456798]\d{2}-3\d{6}$/));
            var regExp2=/(^(010)-3\d{7}|0[23456798]\d{2}-3\d{6}$)/;
             inpt.onblur=function () {
                 console.log(regTest.test(inpt.value));
                 console.log("regExp2.test(inpt.value)"+regExp2.test(inpt.value));

                 console.log("inpt.value"+inpt.value);
                 if(regExp2.test(inpt.value)){
                 // if(reg1.test(inpt.value)){
                     span.innerHTML='您输入的电话号码很正确！';
                     span.className='right';
                 }else if (reg1.test(inpt.value)){
                     span.innerHTML='您输入的手机号码很正确！';
                     span.className='cellphone';
                 } else{
                     span.innerHTML='您输入错误了！';
                     span.className='wrong';
                 }
             }



        }
    </script>
    <body>
    <input type="text" name="" id="">
    <span>您输入的不是正确电话号码</span>
    </body>
    </html>